From: Aki Tuomi Date: Mon, 22 Dec 2025 20:01:18 +0000 (+0200) Subject: [PATCH] lib-regex: Limit number of capture groups correctly X-Git-Tag: archive/raspbian/1%2.4.2+dfsg1-3+rpi1^2~2 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=406a89f1757ab8368fe1cf3040206675091feab3;p=dovecot.git [PATCH] lib-regex: Limit number of capture groups correctly We create at maximum max_capture_groups match groups. Gbp-Pq: Name lib-regex_Limit_number_of_capture_groups_correctly.patch --- diff --git a/src/lib-regex/regex.c b/src/lib-regex/regex.c index 5ccf9d5..d48b48a 100644 --- a/src/lib-regex/regex.c +++ b/src/lib-regex/regex.c @@ -336,12 +336,9 @@ int dregex_code_match_groups(struct dregex_code *code, const char *subject, T_BEGIN { pcre2_match_data *mdata = - pcre2_match_data_create_from_pattern(code->pat, code->gctx); + pcre2_match_data_create(code->max_capture_groups, code->gctx); ret = dregex_code_match_int(code, subject, mdata, error_r); - /* Avoid extracting way too many capture groups */ - if (ret > (int)code->max_capture_groups + 1) - ret = handle_error(PCRE2_ERROR_TOO_MANY_CAPTURES, error_r); - else if (ret > 1) { + if (ret > 1) { bool skip_empty = HAS_ALL_BITS(code->flags, DREGEX_NO_EMPTY_SUB); /* ret is number of groups */ extract_matches((uint32_t)ret, mdata, skip_empty, groups_r);